<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%> 
<%@ page import="wayden.ConnectDB"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%	Integer r2=1;
    String SELECT = "SELECT * FROM Users WHERE login = ? AND password = ?";
    String login = request.getParameter("userName");
    String password = request.getParameter("password");
    
    
    Connection connection = null;
    
    PreparedStatement pstatement = null;
    ConnectDB connectDB = new ConnectDB(); 
    if (login != null && password != null) {
		if (!(login.isEmpty() || password.isEmpty())) {

		    
			
			
			try {
			    connection = connectDB.Connect();
			    
			    Statement st = connection.createStatement();
			    PreparedStatement ps = connection
				    .prepareStatement(SELECT);
			    ps.setString(1, login);
			    ps.setString(2, password);
			    ps.execute();
				ResultSet rs = ps.getResultSet();
				if (rs.next()){
				    session.setAttribute("user", rs.getString(1));
				    //System.err.out(String(session.getAttribute("log")));
				    //session.getAttribute("log");
								    
				%>
<h1 align="center">Congratulation!!! You have been Log In</h1>
<h2 align="center"><a
	
	href="welcome.action?id=<% out.println(rs.getString(1)); %>">Main
page!!!</a></h2>


<%				
				 
				
				}
				else  { %>
<h2 align="center">Invalid login or password</h2>
<% }
				
			    //  out.println(count);
			    connection.close();
			} catch (SQLException ex) {
			    ex.printStackTrace();
			    out.println("Unable to connect to batabase.");
			}

		     catch (Exception e) {
			e.printStackTrace();
		    }
		} else out.println("<center><h2>Enter login and password</h2></center>");
    }
%>
</body>
</html>